package svgedit.gui.actions;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.AbstractAction;

import svgedit.gui.DocPropDialog;
import svgedit.gui.Frame;

/**
 * Action to deal with creating a DocPropDialog and deal with
 * DocPropDialogOptions
 * 
 * @author SARJ
 * 
 */
public class DocPropAction extends AbstractAction implements ActionListener
{
	private static final long serialVersionUID = 2678481066263841513L;
	private DocPropDialog docPropDialog;

	/**
	 * Construct a DocPropAction
	 */
	public DocPropAction()
	{
		super("Document Properties");
	}

	/**
	 * Construct a DocPropAction taking a DocPropDialog
	 * 
	 * @param docPropDialog
	 */
	public DocPropAction(DocPropDialog docPropDialog)
	{
		this.docPropDialog = docPropDialog;
	}

	@Override
	public void actionPerformed(ActionEvent arg0)
	{
		// get the action command from the ActionEvent
		String actionCommand = arg0.getActionCommand();

		if (actionCommand == "Document Properties")
		{
			System.out.println("starting DocPropDialog...");
			docPropDialog = new DocPropDialog();
		}
		else if (actionCommand == "Apply")
		{
			// get the width and height from the user
			double width = docPropDialog.getUserWidth();
			double height = docPropDialog.getUserHeight();

			Frame.getFrame().getView().getDocument().getWidth().setValue(width);
			Frame.getFrame().getView().getDocument().getHeight()
					.setValue(height);
			Frame.getFrame().repaint();

			// close the DocPropDialog
			docPropDialog.dispose();
		}
	}

}
